package fileexplorer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Tools {

	public static void MessageErreur(Shell parent, String message) {
    	final Shell dialog = new Shell(parent);
    	dialog.setLayout(new FillLayout());
    	dialog.setText("Erreur");
    	
    	Composite compV = new Composite(dialog, SWT.FILL);
    	FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
    	fillLayout.marginHeight = 10;
    	fillLayout.marginWidth = 10;
    	fillLayout.spacing = 5;
    	compV.setLayout(fillLayout);
    	
    	Composite compH1 = new Composite(compV, SWT.FILL);
    	compH1.setLayout(new RowLayout(SWT.HORIZONTAL));
    	
    	CLabel lbl = new CLabel(compH1, SWT.NULL);
    	lbl.setText(message);
    	
    	Composite compH2 = new Composite(compV, SWT.FILL);
    	compH2.setLayout(new FillLayout(SWT.HORIZONTAL));
    	
    	Button btnOk = new Button(compH2, SWT.NONE);
    	btnOk.setText("Ok");
    	btnOk.addMouseListener(new MouseListener() {
			@Override public void mouseUp(MouseEvent e) {}
			@Override
			public void mouseDown(MouseEvent e) {
				dialog.close();
			}
			@Override public void mouseDoubleClick(MouseEvent e) {}
		});
    	
    	dialog.pack();
    	dialog.open();
	}

	 public static Display getDisplay() {
	      Display display = Display.getCurrent();
	      //may be null if outside the UI thread
	      if (display == null)
	         display = Display.getDefault();
	      return display;		
	   }
}
